﻿<%
Dim conn
Set conn = Server.CreateObject("ADODB.CONNECTION")
db = "Provider=Microsoft.Jet.OLEDB.4.0;data source="&Server.MapPath("data\data.mdb")&";Jet OLEDB:Database Password=tp@chenkai"
'response.write db
'response.end
conn.Open db

function ulen(byval str)
	Dim RegExpObj,ReGCheck
	Set RegExpObj=new RegExp
	RegExpObj.Pattern="^[\u4e00-\u9fa5|\uFF00-\uFFFF]+$"
	Dim l,t,c,i
	l=Len(str)
	t=l
	For i=1 to l
		c=Mid(str,i,1)
		ReGCheck=RegExpObj.test(c)
		If ReGCheck Then
			t=t+1
		End If
	Next
	Set RegExpObj=nothing
	ulen=t
end function

function ShortDate(ParaName)
	Dim ParaValue
	ParaValue=ParaName
	if ParaValue="" or isnull(ParaValue) then
		ParaValue=""
	else
		If Not IsDate(ParaValue) then
			Response.Write "参数" & ParaName & "必须为日期！"
			Response.End
		Else
			M=Month(ParaValue)
			'if M<10 then M="0"&M
			D=Day(ParaValue)
			'if D<10 then D="0"&D
			ParaValue=M&"-"&D
		End If
	end if
	ShortDate=ParaValue
end function
function ShortTime(ParaName)
	Dim ParaValue
	ParaValue=ParaName
	if ParaValue="" or isnull(ParaValue) then
		ParaValue=""
	else
		If Not IsDate(ParaValue) then
			Response.Write "参数" & ParaName & "必须为日期！"
			Response.End
		Else
			ParaValue=FormatDateTime(ParaValue,4)
		End If
	end if
	ShortTime=ParaValue
end function

'记录派单情况，参数为：车辆id，货单id
function RecordProgress(clid,ybid)
	dim sql
	set cmd_recordprogress=Server.CreateObject("ADODB.Command")
	cmd_recordprogress.ActiveConnection=conn
	'如果承运人为空，则直接删掉派单系统中这张货单
	if clng(clid)=0 then 
		sql="delete * from progress where progress_yb="&ybid
		cmd_recordprogress.CommandText = sql
		cmd_recordprogress.Execute
		'退出函数
		exit function
	end if
	set rs_recordprogress = Server.CreateObject("ADODB.Recordset")
	sql="select progress_id,progress_cl,progress_tx from progress where progress_yb="&ybid
	rs_recordprogress.open sql,conn,1,1
	'检查是否同一张货单派多人
	if not rs_recordprogress.eof then
		'派单系统中存在货单，并且原承运人不同于现在承运人，则修改承运人并重置派单时间
		if clng(rs_recordprogress("progress_cl"))<>clng(clid) then
			if rs_recordprogress("progress_tx")<>"" then
				sql="update progress set progress_cl="&clid&" where progress_yb="&ybid
			else
				sql="update progress set progress_cl="&clid&",progress_start='"&now()&"',progress_accept=null,progress_tx=null,progress_reach=null,progress_left=null,progress_arrival=null,progress_end=null,progress_done=false where progress_yb="&ybid
			end if
			'response.write(sql)
			'response.end
			cmd_recordprogress.CommandText = sql
			cmd_recordprogress.Execute
		end if
	else
		'派单系统中不存在的货单，直接添加
		sql="insert into progress(progress_cl,progress_yb) values("&clid&","&ybid&")"
		cmd_recordprogress.CommandText = sql
		cmd_recordprogress.Execute
	end if
	rs_recordprogress.close
	set rs_recordprogress=nothing
	set cmd_recordprogress=nothing
end function

function CheckRights(post,flag)
	CheckRights=false
	if not session("MM_Reg") then
		'没有登录
		response.write "Error:用户没有登录<br>"
		response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a> "
		response.end
		exit function
	end if
	if not session("MM_Active") then
		'没有登录
		response.write "Error:用户没有激活<br>"
		response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a> "
		response.end
		exit function
	end if
	if Session("MM_Huoyun")="Huoyun" then
		if session("MM_Username")="admin" then
			CheckRights=true
			exit function
		else
			if cpost(session("MM_Post"),post) then
				if vflag(session("MM_Flag"),lpost(session("MM_Post"),post))>=flag then
					CheckRights=true
					exit function
				else
					'操作无访问权限
					response.write "Error:操作无访问权限<br>"
					response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a> "
					response.end
					exit function
				end if
			else
				'岗位无访问权限
				response.write "Error:岗位无访问权限<br>"
				response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a> "
				response.end
				exit function
			end if
		end if
	else
		'货运系统无访问权限
		response.write "Error:货运系统无访问权限<br>"
		response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a> "
		response.end
	end if
	
end function
function CheckPF(post,flag)
	CheckPF=false
	if not session("MM_Reg") then
		'没有登录
		exit function
	end if
	if not session("MM_Active") then
		'没有登录
		exit function
	end if
	if Session("MM_Huoyun")="Huoyun" then
		if session("MM_Username")="admin" then
			CheckPF=true
			exit function
		else
			if cpost(session("MM_Post"),post) then
				if vflag(session("MM_Flag"),lpost(session("MM_Post"),post))>=flag then
					CheckPF=true
					exit function
				else
					'操作无访问权限
					exit function
				end if
			else
				'岗位无访问权限
				exit function
			end if
		end if
	else
		'货运系统无访问权限
	end if
	
end function
function cpost(p,t)
	cpost=false
	p=split(p,",")
	for i=0 to ubound(p)
		if clng(p(i))=t then
			cpost=true
			exit function
		end if
	next
end function

function fpost(t)
	select case t
		case 0 fpost="用户权限"
		case 1 fpost="船务"
		case 2 fpost="车队"
		case 3 fpost="商务"
		case 4 fpost="财务"
	end select
end function

function lpost(p,t)
	lpost=-1
	p=split(p,",")
	for i=0 to ubound(p)
		if clng(p(i))=t then
			lpost=clng(i)
			exit function
		end if
	next
end function

function cflag(f,t)
	cflag=false
	f=split(f,",")
	for i=0 to ubound(f)
		if clng(f(i))=t then
			cflag=true
			exit function
		end if
	next
end function

function fflag(t)
	select case t
	case 1 fflag="查询"
	case 2 fflag="查询、查看"
	case 3 fflag="查询、查看、添加"
	case 4 fflag="查询、查看、添加、编辑"
	case 5 fflag="查询、查看、添加、编辑、删除"
	case 15 fflag="管理员"
	end select
end function

function lflag(f,t)
	lflag=-1
	f=split(f,",")
	for i=0 to ubound(f)
		if clng(f(i))=t then
			lflag=clng(i)
			exit function
		end if
	next
end function

function vflag(f,t)
	vflag=-1
	f=split(f,",")
	if t>-1 and t<=ubound(f) then
		vflag=clng(f(t))
	end if
end function

function utc2time(utc)
	if utc<>"" then
		d=10^(len(cstr(utc))-10)
		cl_timestamp=cdbl(utc)/d
		utc2time=dateadd("s",cl_timestamp,"1970-1-1 0:0:0")
		utc2time=dateadd("h",8,utc2time)
	end if
end function

%>
